// pages/index/success/success.js
import { API_HOST } from "../../../utils/const"
import http from "../../../utils/http"
import util from "../../../utils/util"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    host: API_HOST,
    viewHouseTime: '2018/06/12,2018/06/14,2018/06/17,2018/06/20,2018/06/24',
    cityCode: '',
    preId: '',
    id: '',
    result: false,
    info:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log('====propertyDetailB options.id:', options.preId);
    this.setData({
      preId: options.preId
    });
    this.array();
    // this.setData({
    //   cityCode: wx.getStorageSync('cityCode') || '310100'
    // });

    this.getInfo();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onShow: function () {
  },

  array: function () {
    this.toArray(this.data.viewHouseTime);
  },

  toArray: function(str){
    var arr = str.split(",");
    var newArray = [];//new Array();  
    for (var i = 0; i < arr.length; i++) {
      var arrOne = arr[i].substring(5, 10);
      newArray.push(arrOne);
    }
    console.log('==array newArray:', newArray,newArray.length);
    return newArray;
  },

  getInfo: function () {
    var that = this;
    http({
      url: "/look/insertInfo/v1.0.0",
      data: {
        cityCode: wx.getStorageSync('cityCode') || '310100',
        preprocessId: that.data.preId
      },
      method: 'POST',
      success: function (res) {
        console.log('test test:', res.data);
        if (!res) return;
        that.setData({
          info: res.data,
          id: res.data.id,
          result: res.data.result
        })
      }
    })
  },

  goTel: function (e) {
    let tel = e.currentTarget.dataset.tel;
    wx.makePhoneCall({
      phoneNumber: tel
    })
  },

  goIndex: function(){
    wx.switchTab({
      url: '/pages/index/index'
    })
  },

  goSee: function () {
    wx.navigateTo({
      url: '/pages/appointment/appointmentDetail/appointmentDetail?id=' + this.data.id + '&tasklist=' + this.data.result
    })
  }
})